<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/mi_project/js/jquery.js"></script>
    <script src="/mi_project/js/jquery.cookie.js"></script>
    <script src="/mi_project/js/common.js"></script>
    <link rel="stylesheet" href="/mi_project/css/base.css">
    <link rel="stylesheet" href="/mi_project/css/index-top.css">
    <link rel="stylesheet" href="/mi_project/css/iCenter.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_2917027_4icbe1xja37.css">
    <script src="/mi_project/layui/layui.js"></script>
    <link rel="stylesheet" href="/mi_project/layui/css/layui.css">
</head>

<body>
    <!-- <div id="aaa"></div> -->

    <div class="header-1"></div>
    <div class="header-cart-2">
        <div class="w">
            <div class="loge"><a href=""></a></div>
            <div class="header-nav">
                <h2>个人中心</h2>
            </div>
        </div>
    </div>
    <div class="iCenterMain">
        <div class="w">
            <div class="layui-collapse">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">地址栏<span class="addressAdd">添加</span></h2>
                    <div class="layui-colla-content addressList">
                        <!-- <div class="iCenterBox">
                            <span>淦淞</span>
                            <span>156799207</span>
                            <span>江西省</span>
                            <span>萍乡市</span>
                            <span>上栗县</span>
                            <span
                                class="address">上栗首都王座之下44</span>
                            <div>
                                <span>修改</span>
                                <span>删除</span>
                                <label for="isDefault">设为默认</label>
                                <input type='checkbox' id='isDefault'>
                            </div>
                        </div> -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script>
    // layui.use('element', function () {
    //     var element = layui.element;
    // });
    
    gitAddressList();
    $('.addressAdd').click(function () {
        layer.open({
            skin: 'demo-class',
            type: 2,
            content: 'addressMin.html',
            end: function () {
                gitAddressList()
            }
        });
        return false;
    })
    $(document).on('click', '.addressRemove', function () {
        $.ajax({
            url: urls + '/address/remove',
            data: {
                addressId: $(this).parent().parent().attr('addressid'),
                userId: $.cookie('user').id
            },
            success: function (backData) {
                if (backData.code == 0) {
                    layer.msg('删除成功');
                    gitAddressList()
                } else {
                    layer.msg("异常操作")
                }
            }
        })
    })
    $(document).on('click', '.addressChange', function () {
        localStorage.setItem('addressIdLS', JSON.stringify($(this).parent().parent().attr('addressid')));
        layer.open({
            skin: 'demo-class',
            type: 2,
            content: 'addressMin.html',
            end: function () {
                gitAddressList()
            }
        });
    })
    $(document).on('click', '.isDefault', function () {
        let nowChecked=$(this).prop('checked');
        $('.isDefault').prop('checked',false);
        $(this).prop('checked',nowChecked);
        let _this=$(this);
        $.ajax({
            url: urls + '/address/detail',
            data: {
                addressId: $(this).parent().parent().attr('addressid'),
                userId: $.cookie('user').id
            },
            success: function (backData) {
                let a = _this.prop('checked')*1;
                // console.log(!_this.prop('checked'));
                $.ajax({
                    url: urls + '/address/change',
                    data: {
                        addressId: backData.data.id,
                        consignee: backData.data.consignee,
                        mobile: backData.data.mobile,
                        province: backData.data.province,
                        city: backData.data.city,
                        area: backData.data.area,
                        address: backData.data.address,
                        isDefault: a,
                        userId: $.cookie('user').id
                    },
                    success: function (backData2) {
                        if (backData2.code == 0) {
                            layer.msg('修改成功');
                        } else {
                            layer.msg(backData2.msg)
                        }
                    }
                })
            }
        })
    })
</script>